﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public static class GetFlight
    {

        #region Get Flight
        
        static testdbsEntities ctx = new testdbsEntities();

        public static List<Flight> GetFlights()
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlights(Flight mFlight)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs == mFlight
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlights(Plane mPlane, Instructor mInstrucotr, int mNumber, DateTime mDate)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.fk_plane == mPlane.id_plane && cs.fk_instr == mInstrucotr.id_instr && cs.number == mNumber && cs.date == mDate
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static Flight GetFlightsID(int mNumber)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.number == mNumber
                                             select cs;
                return tFlight.FirstOrDefault<Flight>();
            }
        }

        public static List<Flight> GetFlightsByDate(int mNumber)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.number == mNumber
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByDate(int mNumber, int mId)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.number == mNumber && cs.id_flight == mId
                                             select cs;
                return tFlight.ToList();
            }
        }


        public static List<Flight> GetFlightsByDate(DateTime mDate)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.date == mDate
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByDate(DateTime mStartDate, DateTime mEndDate)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.date >= mStartDate && cs.date <= mEndDate
                                             select cs;
                return tFlight.ToList();
            }
        }



        public static List<Flight> GetFlightsByTime(TimeSpan mStartTime)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.begine_time == mStartTime
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByTime(TimeSpan mEndTime, int alwaysZero)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.end_time == mEndTime
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByTime(TimeSpan mStartTime, TimeSpan mEndTime)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.end_time <= mEndTime && cs.begine_time >= mStartTime
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByPlane(Plane mPlane)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.fk_plane == mPlane.id_plane
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByInstructor(Instructor mInstructor)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.fk_instr == mInstructor.id_instr
                                             select cs;
                return tFlight.ToList();
            }
        }

        public static List<Flight> GetFlightsByCondition(Condition mCondition)
        {
            
            {
                IQueryable<Flight> tFlight = from cs in ctx.Flight
                                             where cs.fk_condition == mCondition.id_condition
                                             select cs;
                return tFlight.ToList();
            }
        }


        #endregion

    }
}
